package vip.meeet.controller.api;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.meeet.bean.Result;
import vip.meeet.bean.ResultHelper;
import vip.meeet.bean.echarts.Option;
import vip.meeet.bean.echarts.Serie;
import vip.meeet.bean.echarts.Xaxis;
import vip.meeet.bean.echarts.Yaxis;
import vip.meeet.bean.echarts.base.ChartType;
import vip.meeet.bean.echarts.base.EchartsBaseData;
import vip.meeet.bean.echarts.base.EchartsData;
import vip.meeet.bean.echarts.base.EchartsDataType;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

@Api(value = "/api", description = "Operations about user")
@RestController
@RequestMapping("/api")
public class DataController {

    @RequestMapping("/one1")
    public Map<String,Object> one1(){
        Integer[] amounts = {5200,93600,520000,1910000,3500000,5710000,9120000,12070000,16820000,21350000,26840000,49820000};//万
        Integer[] year = {2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020};
        HashMap<String, Object> map = new HashMap<>();
        map.put("categories",year);
        map.put("datas",amounts);
        map.put("name","销售额");
        return map;
    }

    @RequestMapping("/option")
    public Result option(){
        Integer[] amounts = {1682,2135,2684,4982};//亿
        Integer[] amounts2 = {1271,1598,2044,2715};//亿
        Integer[] year = {2017,2018,2019,2020};
        Option option = new Option();
        Xaxis xaxis = new Xaxis();
        Yaxis yaxis = new Yaxis();
        yaxis.setName("单位千万时");
        xaxis.setData(Arrays.asList(year));

        LinkedList<Serie> series = new LinkedList<>();
        Serie serie = new Serie();
        serie.setData(Arrays.asList(amounts));
        serie.setName("A");
        series.add(serie);

        serie = new Serie();
        serie.setData(Arrays.asList(amounts2));
        serie.setName("B");
        series.add(serie);

        option.setxAxis(xaxis);
        option.setyAxis(yaxis);
        option.setSeries(series);
        return ResultHelper.getSuccessResult(option);
    }

    @RequestMapping("/base")
    public Result base(){
        Integer[] tm = {1682,2135,2684,4982};//亿
        Integer[] jd = {1271,1598,2044,2715};//亿
        Integer[] year = {2017,2018,2019,2020};
        EchartsData result = new EchartsData();

        EchartsBaseData<Object> x = new EchartsBaseData<>();
        x.setType(EchartsDataType.CATEGORY.getType());
        x.setData(Arrays.asList(year));
        result.setxAxis(Arrays.asList(x));

        EchartsBaseData<Object> y = new EchartsBaseData<>();
        y.setType(EchartsDataType.VALUE.getType());
        y.setName("单位:亿");
        result.setyAxis(Arrays.asList(y));

        LinkedList<EchartsBaseData> data = new LinkedList<>();
        EchartsBaseData<Object> serie = new EchartsBaseData<>();
        serie.setType(ChartType.LINE.getType());
        serie.setName("TM");
        serie.setData(Arrays.asList(tm));

        data.add(serie);
        serie = new EchartsBaseData<>();
        serie.setType(ChartType.LINE.getType());
        serie.setName("JD");
        serie.setData(Arrays.asList(jd));
        data.add(serie);
        result.setSeries(data);

        result.setTitle("天猫京东销售额对比");
        result.setLegend(Arrays.asList("TM","JD"));
        return ResultHelper.getSuccessResult(result);
    }


}
